home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Nejlepší hry
/
Nejlepsi hry.iso
/
hry
/
sea of chaos
/
sea_install.msi
/
_15C39AAA7726369D39812BD40F01CF6A
/
_239CFDB43BF94EBE922B7374EB682994
< prev
next >
Wrap
Text File
|
2005-03-02
|
2KB
|
85 lines
//water vertex shader:
//adjusts alpha based on angle between surface normal and eye
//1 directional light also applied
//also does environmental reflection off water (env map should be fixed relative to axises)
//has projective reflections
//Luke Lenhart
//(C)2004-2005 Digipen Institute of Technology
//world,view,projection transform
float4x4 matWorldViewProj;
//projective mapping matrix (maps projected coords to texture coords)
float4x4 matProjTxt;
//camera position in world space
float4 cameraPos;
//directional light (assumed to be the sun)
float4 lgtDirection;
//shader input
struct VS_INPUT
{
float4 Pos : POSITION;
float4 Normal : NORMAL;
float4 Clr: COLOR0;
};
//shader output
struct VS_OUTPUT
{
float4 Pos : POSITION;
float4 Color : COLOR;
//float2 Tex0 : TEXCOORD0;
float3 EnvTex : TEXCOORD1;
float3 Pos2 : TEXCOORD2;
float4 ProjTxt : TEXCOORD3;
float CamDist : TEXCOORD4;
float CamDist2 : TEXCOORD5;
//float FogClr : TEXCOORD6;
};
//shader code
VS_OUTPUT VShader(VS_INPUT In)
{
VS_OUTPUT Out;
//tex coord generated from position
//Out.Tex0=In.Pos;
//out position
Out.Pos=mul(matWorldViewProj,In.Pos);
Out.Pos2=In.Pos;
//calc directional light color
Out.Color=dot(In.Normal,lgtDirection)*In.Clr;
//calc alpha based dot between vertex normal and vector from vertex to camera
//taken to a high power to spread translucent range over more of the angle range
//done in world space
float3 vecEyeToVertex=normalize(cameraPos-In.Pos);
float alpha=pow(1.0f-dot(vecEyeToVertex,In.Normal), 15.0f);
Out.Color+=alpha*float4(0.2f,0.2f,0.2f,0.0f);
Out.Color.a=(0.6f+alpha)*In.Clr.a*0.8f;
Out.Color+=float4(0.1f,0.1f,0.1f,0.1f);
//calc env reflection vector (done in world space)
float3 tranNorm=In.Normal.xyz;
Out.EnvTex=reflect(-vecEyeToVertex,tranNorm);
//calculation projective texture coordinate
Out.ProjTxt=mul(matProjTxt,In.Pos);
//calc dist from vert to camera
Out.CamDist=distance(cameraPos.xyz,In.Pos.xyz);
Out.CamDist2=sqrt(Out.CamDist);
//calc fog color
//Out.FogClr=saturate(log(Out.CamDist*0.0067f)*0.06f - 0.1f);
//spit out the results
return Out;
}